package com.example.spring_boot_canal.canal;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;

@ConditionalOnProperty( name ="canal.ip", matchIfMissing = false)
@Configuration
public class CanalAutoConfig {

    @Bean
    public CanalConnector canalConnector(CanalConfig config){
        return CanalConnectors.newSingleConnector(
                new InetSocketAddress(config.getIp(), config.getPort()),
                config.getDestination(),
                config.getUsername(),
                config.getPassword());
    }

}
